package com.copractice.data.entity.performance;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.copractice.data.entity.PersistentObject;
import com.copractice.data.entity.question.Question;
import com.copractice.data.entity.user.User;

/**
 * Represents users performance entity which contains all data which relates to answering questions by users.
 * 
 * @author Dmitry Churbanov (dmitry.churbanov@gmail.com)
 * @version 1.0 03/19/2009
 */
@Entity
@Table(name = "USERS_QUESTIONS_PERFORMANCE")
@SuppressWarnings("serial")
public class UsersPerformance extends PersistentObject {

    /**
     * Defines whether question was answered right or not
     */
    private Boolean passed;

    /**
     * Question this performance entity is estimating
     */
    private Question question;

    /**
     * User whom this performance entity belongs to
     */
    private User user;

    /**
     * The score user got answering the question
     */
    private Integer score;

    /**
     * List of attempts of the particular user and for particular question
     */
    private List<UsersQuestionsAttempts> usersQuestionsAttempts;

    /**
     * @see edu.vt.intelligenttutor.data.entity.PersistentObject#getId()
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Override
    public Long getId() {
        return super.getId();
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }

    /**
     * Returns whether question was answered right or not
     * 
     * @return true if the question was answered right, otherwise returns false
     */
    @Column(name = "PASSED")
    public Boolean getPassed() {
        return passed;
    }

    /**
     * Sets whether question was answered right or not
     * 
     * @param passed
     *            the <code>Boolean</code> which defines whether question was
     *            answered right or not
     */
    public void setPassed(Boolean passed) {
        this.passed = passed;
    }

    /**
     * Returns question this performance entity is estimating
     * 
     * @return the <code>Question</code> this performance entity is estimating
     */
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "QUESTION_ID")
    public Question getQuestion() {
        return question;
    }

    /**
     * Sets question this performance entity is estimating
     * 
     * @param question
     *            the <code>Question</code> this performance entity is
     *            estimating
     */
    public void setQuestion(Question question) {
        this.question = question;
    }

    /**
     * User whom this performance entity belongs to
     * 
     * @return the <code>User</code> whom this performance entity belongs to
     */
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "USER_ID")
    public User getUser() {
        return user;
    }

    /**
     * Sets user whom this performance entity belongs to
     * 
     * @param user
     *            the <code>User</code> whom this performance entity belongs to
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * Returns list of users attempts
     * 
     * @return list of users attempts
     */
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "usersPerformance")
    public List<UsersQuestionsAttempts> getUsersQuestionsAttempts() {
        return usersQuestionsAttempts;
    }

    /**
     * Sets list of users attempts
     * 
     * @param usersQuestionsAttempts
     */
    public void setUsersQuestionsAttempts(List<UsersQuestionsAttempts> usersQuestionsAttempts) {
        this.usersQuestionsAttempts = usersQuestionsAttempts;
    }

}
